package com.jiangdg.usbcamera.view;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.jiangdg.usbcamera.R;
import com.jiangdg.usbcamera.login.LoginInfo;
import com.jiangdg.usbcamera.utils.HttpUtils;
import com.jiangdg.usbcamera.utils.SPUtils;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;

import cz.msebera.android.httpclient.Header;

public class CbAdapter extends RecyclerView.Adapter<CbAdapter.MyViewHolder>{
    Context context;
    private View inflater;
    ArrayList<CbBean> list;

    public CbAdapter(Context context, ArrayList<CbBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public CbAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        inflater = LayoutInflater.from(context).inflate(R.layout.item_cblayout,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(inflater);
        return myViewHolder;
//        return new RecyclerView.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        //将数据和控件绑定
        holder.box.setText(list.get(position).getName());


        holder.box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                list.get(position).setChose(b);
            }
        });



    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    //内部类，绑定控件
    class MyViewHolder extends RecyclerView.ViewHolder{

        CheckBox box;
        public MyViewHolder(View itemView) {
            super(itemView);
            box = (CheckBox) itemView.findViewById(R.id.cb);
        }
    }

}
